package com.inno.auth.domain.strategy;

import com.inno.auth.common.enums.LoginTypeEnum;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.EnumMap;
import java.util.List;

/**
 * 登录策略工厂
 *
 * @author sean
 */
@Component
public class LoginHandlerFactory implements InitializingBean {

    @Resource
    private List<LoginHandler> handlerList;

    private final EnumMap<LoginTypeEnum, LoginHandler> handlerMap = new EnumMap<>(LoginTypeEnum.class);
    public  LoginHandler getHandler(LoginTypeEnum type) {
        return handlerMap.get(type);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        handlerList.forEach(handler ->
                handlerMap.put(handler.getType(), handler));
    }
}

